<!DOCTYPE html>
<body>
  <portal src="geolocation-portal.html"></portal>
  <script>
    let requestLocationPromise = undefined;
    function requestLocation() {
      requestLocationPromise = new Promise(r => {
        navigator.geolocation.getCurrentPosition(() => r(true), () => r(false));
      });
    };

    async function activatePortal() {
      let portal = document.querySelector('portal');
      await portal.activate();
      document.body.remove(portal);
    };

    async function queryGeolocationPermission() {
      let status = await navigator.permissions.query({name: 'geolocation'});
      domAutomationController.send(status.state);
    }

    async function waitForRequestLocationToResolve() {
      let result = await requestLocationPromise;
      domAutomationController.send(result);
    }
  </script>
</body>
